# Contributor: Maarten van Gompel <proycon@anaproy.nl>
# Maintainer: Anjandev Momi <anjan@momi.ca>
pkgname=pn
pkgver=0.9.0
pkgrel=4
arch="all"
url="https://github.com/Orange-OpenSource/pn"
pkgdesc="libphonenumber command-line wrapper"
source="https://github.com/Orange-OpenSource/pn/archive/v$pkgver/pn-$pkgver.tar.gz"
license="Apache-2.0"
makedepends="cmake icu-dev libphonenumber-dev gawk"
subpackages="$pkgname-doc $pkgname-gawk"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_CXX_FLAGS="$CXXFLAGS" \
		-DCMAKE_C_FLAGS="$CFLAGS" \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	cd build

	./pn valid +33123456789
	./pn valid -c US '(202) 555-0110'

	./pn valid '(202) 555-0110' && exit 1

	[ "$(./pn format "+1 20 2 555    01 10")"    = "+12025550110" ]
	[ "$(./pn format -c FR "0123456789")"        = "+33123456789" ]
	[ "$(./pn format -c FR -f nat "0123456789")" = "01 23 45 67 89" ]
	[ "$(./pn format -f int "+12025550110")"     = "+1 202-555-0110" ]

	[ "$(./pn find -c "" "+330611234345")" = "+33611234345" ]

	[ "$(./pn find -f nat "2017/04/20: You have 2 messsages, call +1-202-555-0110 to listen to them.")" = "(202) 555-0110" ]

	[ "$(./pn find -c FR "rappelle-moi au 01 23 4 56789 ou au 06 78 90 12 34 après 20h00" | head -1)" = "+33123456789" ]
	[ "$(./pn find -c FR "rappelle-moi au 01 23 4 56789 ou au 06 78 90 12 34 après 20h00" | tail -1)" = "+33678901234" ]
}

package() {
	DESTDIR="$pkgdir" cmake --build build --target install
	mkdir "$pkgdir/usr/share"
	mv "$pkgdir/usr/man" "$pkgdir/usr/share/"
}

gawk() {
	amove usr/lib/gawk
}

sha512sums="
e9b53f3cf689d745b5b6f8bf8700c8ad4b968730ef2982786b8f4c62a031db355e4ff52d632948caf94c2f6070faa3269e4d3971ac646792622cb025c236b580  pn-0.9.0.tar.gz
"
